package com.ohos.connect.devicecloud.mqtt.modular.coap.controller;

import com.ohos.connect.devicecloud.common.pojo.CommonResult;
import com.ohos.connect.devicecloud.mqtt.core.model.dto.CoapToHttpDTO;
import com.ohos.connect.devicecloud.mqtt.core.model.vo.CoapToHttpVO;
import com.ohos.connect.devicecloud.mqtt.modular.coap.service.CoapService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 *  处理Coap通道调用的HTTP
 **/
@RestController()
@RequestMapping(value = "/api/v1/device_cloud/ums/coap")
@Validated
public class CoapHttpController {

    @Resource
    private CoapService coapService;

    // 供coap server调用
    @PostMapping("/http")
    public CommonResult<CoapToHttpVO> coapToHttp(@RequestBody @Valid CoapToHttpDTO coapToHttpDTO) {
        return CommonResult.data(coapService.coapToHttpMethod(coapToHttpDTO));
    }

}
